package com.cn.wx.servlet.login;

import com.cn.wx.model.UserModel;
import com.cn.wx.service.LoginService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/loginUpdate")
public class LoginUpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");

        //通过id，拿到当前id的用户信息
        Integer ids = id == null || id.equals("") ? 0 : Integer.parseInt(id);
        if (ids == 0) {
            resp.sendRedirect("/back/LoginUpdate.jsp");
        } else {
//int a=5>7?6:9;
            LoginService loginService = new LoginService();
            UserModel userModel = loginService.getUserById(ids);
            req.setAttribute("user", userModel);
            req.getRequestDispatcher("/back/LoginUpdate.jsp").forward(req, resp);
        }
    }
}
